package com.example.demo;

import jakarta.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

//@RequestMapping("tes")
//@RestController
@Controller
//@ResponseBody
public class ResponseController {
    @RequestMapping("test")
    public String index(){
        return "/index.html";
    }

    @ResponseBody
    @RequestMapping("text2")
    public String index2(){
        return "返回数据";
    }

    @ResponseBody
    @RequestMapping("test3")
    public HashMap<String ,String > hashMap(){
        HashMap<String ,String > map = new HashMap<>();
        map.put("k1","v1");
        map.put("k1","v1");
        map.put("k1","v1");
        map.put("k1","v1");
        return map;
    }
    @ResponseBody
    @RequestMapping("test4")
    public String setStatus(HttpServletResponse response){
        response.setStatus(418);
        return "设置状态码";
    }

    @ResponseBody
    @RequestMapping(value = "/test5",method = RequestMethod.GET)
    public String setRequest(){
        return "修改请求条件";
    }

    @ResponseBody
    @RequestMapping(value = "/test6",produces = "application/json")
    public String setRequest1(){
        return "{\"ok\":1}";
    }
}
